function Header() {
    this.init();
}
$.extend(Header.prototype, {
    // 初始化
    init() {
        this.loadUser();
        this.addListener();
        this.ss();
        this.weather();
    },
    // 加载登录成功的用户信息
    loadUser() {
        // 从 sessionStorage 中读取登录成功的用户信息
        const user = sessionStorage.username;
        $(".login-success").html( user+",欢迎登录");
    },
    // 注册事件监听
    addListener() {
        $(".link-logout").on("click", this.logoutHandler);
    },
    // 注销处理
    logoutHandler() {
        sessionStorage.removeItem("username");
        location = "/index.html"
    },
    //时钟
    ss(){
        setInterval(function(){
            let date=new Date(),
                year=date.getFullYear(), 
                mon=date.getMonth()+1,  
                day=date.getDate(),     
                hh=date.getHours(),     
                mm=date.getMinutes(),   
                ss=date.getSeconds(),   
                today=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"),
                xq=today[date.getDay()],
                daytime=year +"/"+mon+"/"+day+" "+xq;
            let time;
            if(mm<10 ){
                mm="0"+mm;
                    };
            if(ss<10){
                ss="0"+ss;
                    };
            time="当前时间" + hh+":"+ mm + ":" +ss;
            $(".uu").html(daytime);
            $(".us").html(time);
            },1000);
        },
        //天气
    weather(){
        $.ajax({ url: "http://route.showapi.com/9-2?showapi_appid=75680&showapi_sign=1b3930434bf244b6ba690aa6de032548&area=成都",
            dataType:"json",
            success: function(data){
                const _weather = data.showapi_res_body;
                let t = _weather.now.temperature;
                let w = _weather.now.weather;
                let p = _weather.now.weather_pic;
                var tq = `实时天气：${w} <img id="w_pic" src="${p}">${t}°`;
                $(".weather").html(tq);
            }
        });
    }
});

new Header();
